\documentclass{ctexart}
\usepackage{float}%解决图片乱跑问题
\usepackage{geometry}%设置页面大小边距等
\usepackage{authblk}%作者机构等信息
\usepackage{graphicx}%插入图片
\usepackage{amssymb}%为了用\mathbb
\usepackage{amsmath}%数学方程的显示
\usepackage{listings}%插入代码
\usepackage{fancyhdr}%设置页眉页脚
\usepackage{lastpage}%总页数
\usepackage{tikz}
\usepackage{listings}%插入代码
\usepackage{hyperref}%引用网页
\usepackage{xcolor}%实现代码颜色高亮
\geometry{a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm}%一定要放在前面！
\lstset{frame=single,basicstyle=\ttfamily,columns=flexible,language={C},
keywordstyle=\bf\color{blue},
commentstyle=\it\color[RGB]{0,96,96},
numberstyle=\color[RGB]{0,192,192}}


\pagestyle{fancy}%设置页眉页脚
\lhead{陈冠宇\ 3200102033}%页眉左
\chead{Numerical Analysis}%页眉中
\rhead{HW3}%章节信息
\cfoot{\thepage/\pageref{LastPage}}%当前页，记得调用前文提到的宏包
\rfoot{School of Mathematical Sciences in ZJU}
\renewcommand{\headrulewidth}{0.1mm}%页眉线宽，设为0可以去页眉线
\renewcommand{\footrulewidth}{0.1mm}%页脚线宽，设为0可以去页眉线
\setlength{\headwidth}{\textwidth}

\newtheorem{theorem}{Theorem}
\newtheorem{proof}{Proof}
\newtheorem{solution}{Solution:}
\newtheorem{remark}{Remark}

\hypersetup{%设置网页链接颜色等
    colorlinks=true,%链接将会有颜色，默认是红色
    urlcolor=blue,%链接到网站的链接将会变为蓝绿色（cyan）
    }

\title{Programming Assignments of Chapter2}
\everymath{\displaystyle}
\begin{document}
\section*{Report of Programming Assignments Chapter2}
\subsection*{Introduction}
Enter the folder $Programming\_Pro/src$, and then run the code assignmentI.cpp, then we can have the Interpolation Polynomial output. To get the polynomial,
copy the output polynomial to Geogebra. Geogebra can help me draw the plots. In this report, i have pasted the output result and plots and necessary explanation
 of code.
 \subsection*{Code}
\subsection*{interpolation.h}

\begin{lstlisting}
class HermitePolynomial{
private:
    vector<double> x;
    vector<double> fvalue;
    vector<vector<double>> coef;
    int n;

public:
    HermitePolynomial(vector<double> _x, vector<double> _fvalue, int _n) :
    x(_x), fvalue(_fvalue), n(_n) {}
    void solve(){}          //solve the coefficient
    void outputlist(){}     //print out the diag of the coefficient table
    void outputtable(){}    //print out the coefficient table
    void outputpoly(){}     //print out the polynomial
};
\end{lstlisting}
\subsection*{Result}
\subsection*{A.}
Create interpolation.h.
\subsection*{B.}
\begin{sloppypar}
Here is the result of assignment B.\\
When n = 2:

0.0384615+1.923077E-01(x+5)-3.846154E-02(x+5)x

When n = 4:

0.0384615+3.978780E-02(x+5)+6.100796E-02(x+5)(x+2.5)-2.652520E-02(x+5)(x+2.5)x+5.305040E-03(x+5)(x+2.5)x(x-2.5)

When n = 6:

0.0384615+2.646436E-02(x+5)+2.484537E-02(x+5)(x+3.33333)+1.494458E-02(x+5)(x+3.33333)(x+1.66667)-1.316991E-02(x+5)(x+3.33333)(x+1.66667)x+4.203163E-03(x+5)(x+3.33333)(x+1.66667)x(x-1.66667)-8.406327E-04(x+5)(x+3.33333)(x+1.66667)x(x-1.66667)(x-3.33333)

When n = 8:

0.0384615+2.234280E-02(x+5)+1.395600E-02(x+5)(x+3.75)+1.170427E-02(x+5)(x+3.75)(x+2.5)+6.743376E-04(x+5)(x+3.75)(x+2.5)(x+1.25)-4.896464E-03(x+5)(x+3.75)(x+2.5)(x+1.25)x+2.439642E-03(x+5)(x+3.75)(x+2.5)(x+1.25)x(x-1.25)-6.872230E-04(x+5)(x+3.75)(x+2.5)(x+1.25)x(x-1.25)(x-2.5)+1.374446E-04(x+5)(x+3.75)(x+2.5)(x+1.25)x(x-1.25)(x-2.5)(x-3.75)

The plot is as follows:
\begin{figure}[H]
  \centering
  \includegraphics[width=\linewidth]{figures/geogebra-exportB.png}
  \caption{Runge phenomenon}\label{B}
\end{figure}

\subsection*{C.}
Here is the result of assignment C.

When n = 5:\\
0.0423501-1.690570E-01(x-0.951057)+1.425479E+00(x-0.951057)(x-0.587785)+2.612075E+00(x-0.951057)(x-0.587785)(x-6.12303e-17)+2.746498E+00(x-0.951057)(x-0.587785)(x-6.12303e-17)(x+0.587785)


When n = 10:\\
0.0393884-8.873891E-02(x-0.987688)+1.896786E-01(x-0.987688)(x-0.891007)-5.343052E-01(x-0.987688)(x-0.891007)(x-0.707107)+2.116812E+00(x-0.987688)(x-0.891007)(x-0.707107)(x-0.45399)+8.287432E+00(x-0.987688)(x-0.891007)(x-0.707107)(x-0.45399)(x-0.156434)+1.195431E+01(x-0.987688)(x-0.891007)(x-0.707107)(x-0.45399)(x-0.156434)(x+0.156434)+1.035682E+01(x-0.987688)(x-0.891007)(x-0.707107)(x-0.45399)(x-0.156434)(x+0.156434)(x+0.45399)+5.512772E+00(x-0.987688)(x-0.891007)(x-0.707107)(x-0.45399)(x-0.156434)(x+0.156434)(x+0.45399)(x+0.707107)+8.992497E-16(x-0.987688)(x-0.891007)(x-0.707107)(x-0.45399)(x-0.156434)(x+0.156434)(x+0.45399)(x+0.707107)(x+0.891007)

When n = 15:\\
0.0388699-8.006751E-02(x-0.994522)+1.349612E-01(x-0.994522)(x-0.951057)-2.314980E-01(x-0.994522)(x-0.951057)(x-0.866025)+4.491577E-01(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)-1.047531E+00(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)+2.339442E+00(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)+1.402834E+01(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)(x-0.207912)+6.935388E+00(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)(x-0.207912)(x-6.12303e-17)-4.753585E+01(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)(x-0.207912)(x-6.12303e-17)(x+0.207912)-1.406278E+02(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)(x-0.207912)(x-6.12303e-17)(x+0.207912)(x+0.406737)-2.357562E+02(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)(x-0.207912)(x-6.12303e-17)(x+0.207912)(x+0.406737)(x+0.587785)-3.022076E+02(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)(x-0.207912)(x-6.12303e-17)(x+0.207912)(x+0.406737)(x+0.587785)(x+0.743145)-3.317914E+02(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)(x-0.207912)(x-6.12303e-17)(x+0.207912)(x+0.406737)(x+0.587785)(x+0.743145)(x+0.866025)-3.336190E+02(x-0.994522)(x-0.951057)(x-0.866025)(x-0.743145)(x-0.587785)(x-0.406737)(x-0.207912)(x-6.12303e-17)(x+0.207912)(x+0.406737)(x+0.587785)(x+0.743145)(x+0.866025)(x+0.951057)

When n = 20:\\
0.0386906-7.731360E-02(x-0.996917)+1.207710E-01(x-0.996917)(x-0.97237)-1.789300E-01(x-0.996917)(x-0.97237)(x-0.92388)+2.715086E-01(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)-4.414577E-01(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)+7.854712E-01(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)-1.445651E+00(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)+1.113646E+00(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)+2.379547E+01(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)-2.412796E+01(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)-3.314515E+02(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)-9.659005E+02(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)(x+0.233445)-1.734364E+03(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)(x+0.233445)(x+0.382683)-2.309921E+03(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)(x+0.233445)(x+0.382683)(x+0.522499)-2.462382E+03(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)(x+0.233445)(x+0.382683)(x+0.522499)(x+0.649448)-2.166917E+03(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)(x+0.233445)(x+0.382683)(x+0.522499)(x+0.649448)(x+0.760406)-1.552441E+03(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)(x+0.233445)(x+0.382683)(x+0.522499)(x+0.649448)(x+0.760406)(x+0.85264)-7.883263E+02(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)(x+0.233445)(x+0.382683)(x+0.522499)(x+0.649448)(x+0.760406)(x+0.85264)(x+0.92388)+3.592209E-12(x-0.996917)(x-0.97237)(x-0.92388)(x-0.85264)(x-0.760406)(x-0.649448)(x-0.522499)(x-0.382683)(x-0.233445)(x-0.0784591)(x+0.0784591)(x+0.233445)(x+0.382683)(x+0.522499)(x+0.649448)(x+0.760406)(x+0.85264)(x+0.92388)(x+0.97237)


\begin{figure}[H]
  \centering
  \includegraphics[width=\linewidth]{figures/geogebra-exportC.png}
  \caption{Runge phenomenon}\label{C}
\end{figure}

\subsection*{D.}
Here is the result of assignment D.

0+7.500000E+01*x+0.000000E+00*x*x+2.222222E-01*x*x(x-3)-3.111111E-02*x*x(x-3)(x-3)-6.444444E-03*x*x(x-3)(x-3)(x-5)+2.263889E-03*x*x(x-3)(x-3)(x-5)(x-5)-9.131944E-04*x*x(x-3)(x-3)(x-5)(x-5)(x-8)+1.305268E-04*x*x(x-3)(x-3)(x-5)(x-5)(x-8)(x-8)-2.022363E-05*x*x(x-3)(x-3)(x-5)(x-5)(x-8)(x-8)(x-13)

(a)By Geogebra, we have f(10) = 742.5 and f'(10) = 48.38;

(b)By Geogebra, we have the plot:
\begin{figure}[H]
  \centering
  \includegraphics[width=\linewidth]{figures/geogebra-exportD.png}
  \caption{Speed-Time}\label{D}
\end{figure}

By the plot we notice that when $t\in [0,13],\exists t\ s.t.\ f(t)>81$ That is the car exceeds the speed limit.


\subsection*{E.}
(a)the average weight of samples are:

6.67+1.771667E+00*x+4.578333E-01*x(x-6)-1.247784E-01*x(x-6)(x-10)+1.356603E-02*x(x-6)(x-10)(x-13)-9.780852E-04*x(x-6)(x-10)(x-13)(x-17)+4.147705E-05*x(x-6)(x-10)(x-13)(x-17)(x-20)

6.67+1.571667E+00*x-8.716667E-02*x(x-6)-1.527289E-02*x(x-6)(x-10)+2.579078E-03*x(x-6)(x-10)(x-13)-2.048042E-04*x(x-6)(x-10)(x-13)(x-17)+8.676802E-06*x(x-6)(x-10)(x-13)(x-17)(x-20)

(b)By Geogebra,
$$\begin{aligned}
Sample1-Averge-Weight &= f(43) = 14640.26\\
Sample2-Averge-Weight &= g(43) = 2981.48
\end{aligned}$$
\begin{remark}
From the plot as follows, we notice that larvae of sample 1 die quickly after their birth, and then they come back to life on about Day5.

\end{remark}
\begin{figure}[H]
  \centering
  \includegraphics[width=\linewidth]{figures/geogebra-exportE.png}
  \caption{Weight-Days}\label{}
\end{figure}

\subsection*{Summary}
That is all. Thanks for reading.
\end{sloppypar}
\end{document}
